<?php 
/**
 * 分类列表页面
 */
namespace Home\Controller;
use Hdphp\Library\Controller;


Class ListController extends CommonController{
	

	public function index(){

		//读取顶级分类
		$this->topNav();

		//获取当前栏目的分类
		$cid= isset($_GET['cid']) ? (int) $_GET['cid'] : 0;
		$sql="SELECT * FROM hd_category WHERE pid='{$cid}' ";
		if(!M()->query($sql)){
			$cid=0;
		}

		$sql="SELECT * FROM hd_category WHERE pid='{$cid}' ";
		$category=M()->query($sql);
		//如果查询不到子分类
		if(!$category){
			//获取父级id
			$sql = "SELECT pid FROM hd_category WHERE cid={$cid}";
			$pid = M()->query($sql);
			$pid = $pid[0]['pid'];

			//找同级id分类
			$sql="SELECT * FROM hd_category WHERE pid={$pid} ";
			$category=M()->query($sql);
		}

		$this->assign('category',$category);

		//获取问题类型 w 问题类型
		$w=isset($_GET['w']) ? intval($_GET['w']) : 0;
		switch ($w) {
			case 0:
				//如果是全部分类 各种类型问题显示 否则显示对应栏目的问题
				$where= $cid==0 ? "solve=0" : "solve=0 AND c.cid={$cid} "; 
				break;

			case 1:
				//如果全部分类 显示已经解决的所有问题，否则显示当前分类问题
				$where= $cid==0 ? "solve=1" : "solve=1 AND c.cid={$cid} "; 
				break;	

			case 2:
				$where= $cid==0 ? "reward>=50" : "reward>=50 AND c.cid={$cid} "; 
				break;

			case 3:
				$where= $cid==0 ? "answer=0" : "answer=0 AND c.cid={$cid} "; 
				break;
		}
		//关联问题分类
		$sql="SELECT * FROM hd_ask a JOIN hd_category c ON a.cid=c.cid WHERE {$where}";
		$askData=M()->query($sql);
		// p($askData);die;
		$this->assign('askData',$askData);

		//处理面包屑导航
		$this->Breadcrumbs($cid);

		//问答右部统计信息
		$this->rightInfo();

		$this->display();
	}





}

 ?>